﻿using BepInEx;
using CheatMenu.Managers;
using CheatMenu.Menus;
using Logger = BepInEx.Logging.Logger;
using BepInEx.Logging;
using System.Collections;
using System;
using UnityEngine;
using CheatMenu.Utils;

namespace CheatMenu
{
    [BepInPlugin(PluginName, PluginName, Version)]
    public class CheatMenuPlugin : BaseUnityPlugin
    {
        //Constants
        public const string PluginName = "CheatMenuPlugin";
        public const string Version = "1.0.7";
        
        private MenuCheat CheatMenu;
        private MenuConfig ConfigMenu;
        private MenuStateViewer StateViewerMenu;
        private MenuDebug DebugMenu;
        private MenuLoadScene LoadSceneMenu;
        private MenuRandomIntegerPicker RandomIntegerPickerMenu;
        private MenuScreenshot ScreenshotMenu;
        private MenuCommands CommandsMenu;
        private MenuNotifications NotificationMenu;

        public CheatMenuPlugin()
        {
            LogManager.Initialize(Logger);
            CheatMenuPatcher.PatchAll();
        }

        protected void Awake()
        {
            GUIManager.Initialize(this);
            StateManager.Initialize();
            BindManager.Initialize(this);

            CheatMenu = new MenuCheat { Draggable = true };
            StateViewerMenu = new MenuStateViewer();
            ConfigMenu = new MenuConfig { Draggable = true };
            DebugMenu = new MenuDebug { Draggable = true };
            LoadSceneMenu = new MenuLoadScene { Draggable = true };
            RandomIntegerPickerMenu = new MenuRandomIntegerPicker { Draggable = true };
            ScreenshotMenu = new MenuScreenshot { Draggable = true };
            CommandsMenu = new MenuCommands { Draggable = true };
            NotificationMenu = new MenuNotifications();

            KeyCode cheatBind = BindManager.GetBoundKeyForMenu(CheatMenu);
            NotificationMenu.PushNotification($"{PluginName} {Version} Loaded", cheatBind != KeyCode.None ? $"Hit {cheatBind} to toggle the menu" : "No key bound!");
        }

        protected void OnGUI()
        {
            MenuManager.OnGUI();
        }

        protected void Update()
        {
            StateManager.OnUpdate();         
            MenuManager.OnUpdate();
            BindManager.OnUpdate();
        }
    }
}
